home *** CD-ROM | disk | FTP | other *** search
- Path: news.mindlink.net!uniserve!usenet
- From: nowher@anyplace.com (Chris)
- Newsgroups: comp.lang.c++
- Subject: Help! I am baffled! (newbie) - problem.txt [1/1]
- Date: 3 Feb 1996 04:38:35 GMT
- Organization: UNIServe Online
- Distribution: world
- Message-ID: <4euosb$qnj@atlas.uniserve.com>
- NNTP-Posting-Host: van0300.tvs.net
- Mime-Version: 1.0
- Content-Type: multipart/mixed;
- Boundary="*-*-*- Next Section -*-*-*"
- X-Newsreader: WinVN 0.99.2
-
- --*-*-*- Next Section -*-*-*
-
- I think I got a doozy here.
-
- --*-*-*- Next Section -*-*-*
-
- I'll do my best to explain this problem. The structure
- below, Tpart, is declared in the global area of the program.
- The rest of the sample here is in a seperate function.
- Ok, in the first input block (PartNum), the input goes into
- TempStr. Fine. With the section marked with ***** commented
- out, the output at the bottom is as expected. Whatever the
- user types is output correctly.
-
- The problem I have is when I de-comment the block marked by
- *****. The output at the bottom is not correct.
- TempPart.PartNum is somehow changed by the following input block.
- There are no explicit TempPart.PartNum= declarations, but the
- output for PartNum is the same as Length. Except for this, my
- program so far works fine.
-
- eg: input by user:
- PartNum:( PartA123 )
- Length:( 123 )
-
- output by program:
- Part Num:123<-
- Length:123<-
-
- when it *should* be:
- Part Num:PartA123<-
- Length:123
-
- I am baffled by this. Please help.
-
-
-
- Here are the relevant parts of my program:
-
- typedef struct Tpart{
- char *PartNum;
- unsigned int Length;
- unsigned int Width;
- char *Material;
- char Sugg;
- Tpart *CrossRef1,*CrossRef2,*NextPart;
- }; // sizeof=52 bytes
-
- [snip]
-
- Tpart *Head=PartHead; // Local pointer to determine current position in list
- Tpart TempPart; // Local var for input of field data
- char TempStr[20];
- char ch;
- int x=0;
-
- // Init TempPart
- TempPart.PartNum = new char[15];
- TempPart.Length =0;
- TempPart.Width =0;
- TempPart.Material = new char[20];
- TempPart.Sugg =0;
-
- [snip]
-
- // take input for fields
- // ----input PartNum:
- gotoxy(21,5); // position cursor at first field
- ch=' ';
- x=0;
- while (ch != '\r'){ // by the way, this is my solution to the newbie
- ch=getche(); // input problem of a few days ago.
- if (!iscntrl(ch) && wherex()<37) TempStr[x++]=ch;
- else switch(ch){
- case '\r':TempStr[x]=NULL;break;
- case '\b':x--;break;
- default:cout << '\b';beep(); // beep is a harmless function which does just that.
- }
- }
- TempPart.PartNum=TempStr;
-
- *****
- //-----input Length:
- gotoxy(21,6); // position cursor at Length field
- ch=' ';
- x=0;
- while (ch != '\r'){
- ch=getche();
- if (isdigit(ch) && wherex()<27) TempStr[x++]=ch;
- else switch(ch){
- case '\r':TempStr[x]=NULL;break;
- case '\b':x--;break;
- case '-':if (x==0)TempStr[x++]=ch;break;
- default:cout << '\b';beep();
- }
- }
- TempPart.Length=atoi(TempStr);
-
- *****
-
- // the output here is for de-bugging purposes only.
- gotoxy(1,16);
- cout << "Part Num:" << TempPart.PartNum << "<-";
- cout << "\nLength:" << TempPart.Length << "<-";
- cout << "\nWidth:" << TempPart.Width << "<-";
- cout << "\nMaterial:" << TempPart.Material << "<-";
- cout << "\nOK? " << TempPart.Sugg << "<-";
- --*-*-*- Next Section -*-*-*--
-
-